<?php
namespace Home\Controller;
use Think\Controller;
class ContactController extends Controller {
	public function index(){

		if(isset($_SESSION['username'])){
        	$this->assign('login','true');
        	$this->assign('username',$_SESSION['username']);
        }

        //当前登录用户的id
        $userId=$_SESSION['id'];

 

		$this->display();
	}

     //退出
    public function doLogout(){
        $_SESSION = array();
        if(isset($_COOKIE[session_name()])){
            setcookie(session_name(),'',time()-1,'/');
        }
        session_destroy();
        $this->redirect('Index/index');
    }

    //添加留言
    public function doMessage(){
        
        $message = D('message');
        if(!$message->create()){
                $this->error($message->getError());
            }

            $lastId = $message->add();
            if ($lastId){
                $this->success('留言成功',U('Contact/Index'));
            }else {
                $this->error('留言失败，请返回！');
            }
        }
}